#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 1e4 + 10, M = 1e6 + 10;

int n;
int ne[N * 55], cnt[N * 55], q[N * 55]; 
int tr[N * 55][26], idx;
char str[M];

void insert(){
    int p = 0;
    for(int i = 0; str[i]; i ++){
        int k = str[i] - 'a';
        if(!tr[p][k]) tr[p][k] = ++idx;
        p = tr[p][k];
    }
    cnt[p] ++;
}


void build(){
    int hh = 0, tt = -1;
    for(int i = 0; i < 26; i ++){
        if(tr[0][i]) q[++tt] = tr[0][i];
    }

    while(hh <= tt){
        int t = q[hh++];
        for(int i = 0; i < 26; i ++){
            int p = tr[t][i];
 

            // int j = ne[t];
            // while(j && !tr[j][i]) j = ne[j];
            // if(tr[j][i]) j = tr[j][i];

            // ne[c] = j;
            // q[++tt] = c;

            //总结如果我存在，我就接到之前的父亲节点的ne节点上，如果我不存在那么我就做嫁衣来指向上一个
            if(!p) tr[t][i] = tr[ne[t]][i];
            else {
                ne[p] = tr[ne[t]][i];
                q[++tt] = p;
            }
        }
    }
}

void solve(){
    memset(ne, 0, sizeof ne);
    memset(tr, 0, sizeof tr);
    memset(cnt, 0, sizeof cnt);
    int res = 0;
    idx = 0;

    scanf("%d", &n);
    for(int i = 0; i < n; i ++){
        scanf("%s", str);
        insert();
    }

    build();

    scanf("%s", str);
    for(int i = 0, j = 0; str[i]; i ++){
        int t = str[i] - 'a';
        j = tr[j][t];

        int p = j;
        while(p){
            res += cnt[p];
            cnt[p] = 0; 
            p = ne[p];
        }
    }


    printf("%d\n", res);
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        solve();
    }

    return 0;
}